package com.job.ZhangMeng.Homework0715;

import java.util.Arrays;

public class String04 {

    public static void main(String[] args) {
        String name = "lucy_lili_luck";
        String newName = name.replace('l', 'L');  //以新字符全部替换旧字符
        System.out.println(newName);
        String newName2 = name.replace("li", "WE");  //以新子串全部替换旧子串
        System.out.println(newName2);

        String[] names = name.split("_"); //以"_"为分割,依次存入names[]
        System.out.println(Arrays.toString(names));
        String[] names2 = name.split("_", 2); //以"_"为分割,分为两部分,依次存入names[]
        System.out.println(Arrays.toString(names2));

        //subString()截取子字符串
        //subString(from)方法,以[from,∞)的形式,从起始下标开始截取到末尾
        //subString(from,to)方法,以[from,to)的形式,从起始下标开始截取到终止下标
        String url = "http://www.winter.com/news/login.action";
        int index=url.indexOf("www");
        int indexSlash=url.indexOf("/", index);
        String host=url.substring(index,indexSlash);
        System.out.println(host);
        System.out.println(url.toUpperCase());

        String userName="  Lazar Kaganovich   ";
        System.out.println(userName.length());
        userName=userName.trim();   //去除两侧的空白
        System.out.println(userName.length());

    }
}
